<?php
	/*
	 *开放API接口
	 */
	
	class tsApi{
		
		/*
		 *POST方式
		 */
		 
		function post($arrData,$apiUrl){
			
			$data = http_build_query($arrData);  
			
			$opts = array(
				'http'	=>array(
					'method'	=>"POST",
					'header'		=>"Content-type: application/x-www-form-urlencoded\r\n".
							   "Content-length:".strlen($data)."\r\n" .
							   "Cookie: foo=bar\r\n" .
							   "Content-type: text/html; charset=utf-8\r\n".
							   "\r\n",  
					'content' 	=> $data,
				)  
			);  
			
			$cxContext = stream_context_create($opts);
			ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)');
			$jsonData	= file_get_contents($apiUrl,false,$cxContext);
			
			$arrJson = json_decode($jsonData);
			
			return $arrJson;
			
		}
		
		function curl_post($arrData,$apiUrl){
			
			extract($_POST) ;  

			foreach($arrData as $key=>$value) { 
				$fields_string .= $key.'='.$value.'&' ; 
			} 
			rtrim($fields_string ,'&') ; 

		
			$ch = curl_init() ; 
			
			curl_setopt($ch, CURLOPT_URL,$apiUrl) ;
			curl_setopt($ch, CURLOPT_POST,count($arrData)) ;
			curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string) ; 
			
			$result = curl_exec($ch);
			
			curl_close($ch);
			
			$result = json_decode($result);
			
			return $result;
			
		}
		
	}